class PrintDemo {
	
	//private String rr;
	
	/*
	PrintDemo (String pp){
	   rr = pp;
	   System.out.println("PrintDemo class " + rr);
	}
	*/
	
   public void printCount(){
    try {
         for(int i = 5; i > 0; i--) {
            //System.out.println(rr + " Counter "  + i );
            System.out.println("Counter "  + i );
         }
     } catch (Exception e) {
         System.out.println("Thread  interrupted.");
     }
   }

}

class ThreadDemo extends Thread {
   private Thread t;
   private String threadName;
   PrintDemo  PD;

   ThreadDemo( String name,  PrintDemo pd){
       threadName = name;
        PD = pd;
   }

   public void run() {
	 //System.out.println("Thread " +  threadName + " entering.");  
     PD.printCount();
     System.out.println("Thread " +  threadName + " exiting.");
   }

   /*
   public void runrun() {
		 System.out.println("Runrun " +  threadName + " entering.");  
	     PD.printCount();
	     System.out.println("Runrun " +  threadName + " exiting.");
	   }
   */
   
   public void demoStart ()
   {
      System.out.println("Starting Thread " +  threadName );
      if (t == null)
      {
    	 //runrun();
    	 t = new Thread (this, threadName);
         t.start ();
      }
   }

}

public class With_out_Synchronization {
   public static void main(String args[]) {

	  PrintDemo PD = new PrintDemo();
	  //PrintDemo PDa = new PrintDemo("aa");
      //PrintDemo PDb = new PrintDemo("bb");

      ThreadDemo T1 = new ThreadDemo( "One", PD );
      ThreadDemo T2 = new ThreadDemo( "Two", PD );
      //ThreadDemo T1 = new ThreadDemo( "One", PDa );
      //ThreadDemo T2 = new ThreadDemo( "Two", PDb );

      T1.demoStart();
      T2.demoStart();

      // wait for threads to end
      try {
         T1.join();
         T2.join();
      } catch( Exception e) {
         System.out.println("Interrupted");
      }
   }
}